package com.android.aqq.bean;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

public class ChatState implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6775987118302043167L;
	private QQBuddy buddy = null;
	private QQGroup qqGroup = null;
	private int type;
	private List<QQMessage> messageList; //消息
	private int unread;
	private ViewHolder mHolder;
	
	public ChatState(QQBuddy buddy) {
		this.buddy = buddy;
		this.type = 1;
		this.messageList = new LinkedList<QQMessage>();
		this.unread = 0;
	}
	
	public int getUnread() {
		return unread;
	}

	public void setUnread(int unread) {
		this.unread = unread;
	}

	public ChatState(QQGroup qqGroup) {
		this.qqGroup = qqGroup;
		this.type = 2;
		this.messageList = new LinkedList<QQMessage>();
		this.unread = 0;
	}
	
	
	/**
	 * 新消息加入队列
	 * @param message
	 */
	public synchronized void addMessage(int sender, String message, boolean flag) {
		messageList.add(new QQMessage(sender, message));
		if (flag) {
			unread ++;
			if (mHolder!=null) {
				mHolder.mMessage.setText("[" + unread + "]");
			}
		}
	}
	
	public void resetNewMessageCount() {
		unread =0 ;
		if (mHolder!=null) {
			mHolder.mMessage.setText("[" + unread + "]");
		}
	}

	public int getId() {
		switch(type) {
		case 1:
			return buddy.getQQ();
		case 2:
			return qqGroup.getClusterId();
		default:
			return 0;
		}
	}

	public String getNick() {
		return buddy.getNick();
	}

	public List<QQMessage> getMessageQueue() {
		return messageList;
	}


	public String getName() {
		return buddy.getName();
	}


	public QQBuddy getBuddy() {
		return buddy;
	}


	public void setBuddy(QQBuddy buddy) {
		this.buddy = buddy;
	}

	public void setQQGroup(QQGroup qqGroup) {
		this.qqGroup = qqGroup;
	}

	public int getType() {
		return type;
	}

	public QQGroup getQQGroup() {
		return qqGroup;
	}

	public ViewHolder getHolder() {
		return mHolder;
	}

	public void setHolder(ViewHolder holder) {
		mHolder = holder;
	}
}
